<?php
if ($_SERVER['REDIRECT_URL'] == "/")
{
    $_SERVER['REDIRECT_URL'] = "/boot/boot.debentu.php";
}

$path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REDIRECT_URL'];

if (file_exists($path))
{
    define("ROOT", $_SERVER['DOCUMENT_ROOT']);
    $mime_type = mime_content_type($path);

    if (preg_match("/\.js$/", $path))
	$mime_type = "application/javascript";

    if ($mime_type == "text/javascript") // Względy estetyczne, aby w "drzewku" było ładniej
	$mime_type = "application/javascript";

    /* Drzewko strumieni */
    if ($mime_type == "application/javascript")
        include ROOT."/bin/preprocessor.php";

    /* IMAGE */
    else if ($mime_type == "image/png")
	include ROOT."/bin/send/send.image.png.php";
    else if ($mime_type == "image/jpeg")
	include ROOT."/bin/send/send.image.jpeg.php";
    else if ($mime_type == "image/gif")
	include ROOT."/bin/send/send.image.gif.php";

    /* TEXT */
    else if ($mime_type == "text/plain")
	include ROOT."/bin/send/send.text.plain.php";
    else if ($mime_type == "text/html")
	include ROOT."/bin/send/send.text.html.php";
    else if ($mime_type == "text/x-php")
	include ROOT."/bin/send/send.text.x-php.php";
    
    /* OTHER */
    else if ($mime_type == "directory")
	include ROOT."/bin/send/send.directory.php";

    /* Is not supported */
    else {
	header("Content-type: text/plain; charset: utf-8"); print "This MIME type ${mime_type} is not supported.";
    }
}
else
{
    header("HTTP/1.1 404 Not Found");
    header("Content-Type: text/plain; charset=utf-8");
}
?>
